package com.cyt.web.controller.${module?replace('/', '.')};

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.${module?replace('/', '.')}.model.vo.${entity}Vo;
import com.cyt.${module?replace('/', '.')}.service.${entity}Service;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import org.apache.commons.lang.StringUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * ${tableComment}控制层
 *
 * @author ${author}
 * @date ${.now}
 */
@RestController
public class ${entity}Controller extends BaseController {

    @Resource
    private ${entity}Service ${entity?uncap_first}Service;
    
    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author ${author}
     * @date ${.now}
     */
    @RequestMapping("/${module}/${entity?replace(module,'')?lower_case}/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 分页查询
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/findPage", method = RequestMethod.POST)
    public ReturnResult findPage(${entity}Vo ${entity?uncap_first}Vo, int page, int limit) {
        return ${entity?uncap_first}Service.findPage(${entity?uncap_first}Vo, page, limit);
    }

    /**
     * 分页查询
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/findVoPage", method = RequestMethod.POST)
    public ReturnResult findVoPage(${entity}Vo ${entity?uncap_first}Vo, int page, int limit) {
        return ${entity?uncap_first}Service.findVoPage(${entity?uncap_first}Vo, page, limit);
    }

    /**
     * list查询
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "list查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/findList", method = RequestMethod.POST)
    public ReturnResult findList(${entity}Vo ${entity?uncap_first}Vo) {
        return new ReturnResult(${entity?uncap_first}Service.findList(${entity?uncap_first}Vo));
    }

    /**
     * list查询
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "list查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/findVoList", method = RequestMethod.POST)
    public ReturnResult findVoList(${entity}Vo ${entity?uncap_first}Vo) {
        return new ReturnResult(${entity?uncap_first}Service.findVoList(${entity?uncap_first}Vo));
    }

    /**
     * 单个对象查询
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "one查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/findOne", method = RequestMethod.POST)
    public ReturnResult findOne(${entity}Vo ${entity?uncap_first}Vo) {
        return new ReturnResult(${entity?uncap_first}Service.findOne(${entity?uncap_first}Vo));
    }

    /**
     * 单个对象查询
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "one查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/findVoOne", method = RequestMethod.POST)
    public ReturnResult findVoOne(${entity}Vo ${entity?uncap_first}Vo) {
        return new ReturnResult(${entity?uncap_first}Service.findVoOne(${entity?uncap_first}Vo));
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(${entity}Vo ${entity?uncap_first}Vo) {
        ModelAndView view = new ModelAndView("/${module}/${entity?replace(module,'')?lower_case}/${entity?uncap_first}Edit");
        if (StringUtils.isNotBlank(${entity?uncap_first}Vo.getId())) {
            view.addObject(${entity?uncap_first}Service.findVoOne(${entity?uncap_first}Vo));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, ${entity}Vo ${entity?uncap_first}Vo) {
        return ${entity?uncap_first}Service.addOrUpdate(${entity?uncap_first}Vo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, ${entity}Vo ${entity?uncap_first}Vo) {
        return ${entity?uncap_first}Service.remove(${entity?uncap_first}Vo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param ${entity?uncap_first}Vo 接受参数对象
     * @return ReturnResult
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}", classz = "${classLogName}", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/${module}/${entity?replace(module,'')?lower_case}/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, ${entity}Vo ${entity?uncap_first}Vo) {
        return ${entity?uncap_first}Service.delete(${entity?uncap_first}Vo, acceptCurrentUser(request));
    }
}